import request from '@/utils/request'
import type { ICategory, IAttrValue } from './types'

enum API {
  CATEGORY1_URL = '/admin/product/getCategory1',
  CATEGORY2_URL = '/admin/product/getCategory2/',
  CATEGORY3_URL = '/admin/product/getCategory3/',

  ATTRINFO_LIST_URL = '/admin/product/attrInfoList/',
  SAVEATTR_URL = '/admin/product/saveAttrInfo/', // 新增属性或修改属性
  DELETEATTR_URL = '/admin/product/deleteAttr/'
}

export const reqCategory1 = () => request.get<any, Common<ICategory[]>>(API.CATEGORY1_URL)
export const reqCategory2 = (cateId1: number) => request.get<any, Common<ICategory[]>>(API.CATEGORY2_URL + cateId1)
export const reqCategory3 = (cateId2: number) => request.get<any, Common<ICategory[]>>(API.CATEGORY3_URL + cateId2)

export const reqAttrInfoList = (cate1Id: number, cate2Id: number, cate3Id: number) =>
  request.get<any, Common<IAttrValue[]>>(API.ATTRINFO_LIST_URL + `${cate1Id}/${cate2Id}/${cate3Id}`)
export const reqAddOrUpdateAttr = (data: IAttrValue) => request.post<any, any>(API.SAVEATTR_URL, data)
export const reqDeleteAttr = (id: number) => request.delete<any, Common<null>>(API.DELETEATTR_URL + id)
